﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Formatting;
using Microsoft.VisualStudio.Language.Intellisense;
using WindowsInput;
using System;

namespace pyInt
{
    internal class Formator
    {
        ICompletionBroker m_completionBroker;
        ITextView m_textwiew = null;

        public void OnTextContentChanged(object sender, TextContentChangedEventArgs e)
        {
            if (e.Changes.Count != 1)
                return;
            ITextChange lastTextChange = e.Changes[0];
            if (lastTextChange.NewText.Length != 1)
                return;
            char changedChar = lastTextChange.NewText[0];
            if ((changedChar >= 'a' && changedChar <= 'z') ||
                (changedChar >= 'A' && changedChar <= 'Z') )
            {
                if (!m_completionBroker.IsCompletionActive(m_textwiew))
                {
                    KeyboardSimulator keySim = new KeyboardSimulator();
                    keySim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.CONTROL,
                        WindowsInput.Native.VirtualKeyCode.VK_J);
                }
            }
            return;
        }

        public Formator(ITextView textview, ICompletionBroker completeBroker)
        {
            m_textwiew = textview;
            m_completionBroker = completeBroker;
        }
    }
}
